<?php 
include '../data/data.php';
include '../data/ip.php';
$user=$_SESSION['user']; //获取到的用户名
$pass=$_SESSION['pass']; //获取到的密码
$type=$_POST['type']; //kmlx
$ka=$_POST['ka']; //CDK激活码
$date=date("Y-m-d");  //时间
$result= mysql_query("SELECT * FROM user WHERE username='$user' and password='$pass'", $link);  
$row = mysql_fetch_array($result);
if($row[id]==''){
	header('location:/user/login.html?fwd=/pay/deposit.html');
}
if($_SERVER['REQUEST_URI']!='/pay/cdk' & $_SERVER['REQUEST_URI']=='/pay/cdk.php'){
	exit('<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /pay/cdk.html was not found on this server.</p>
<hr>
<address>Apache Server at www.81im.com Port 80</address>

</body></html>');
}
?>
<?php 
if($type!='cdk'){
    $returndata = array("errcode"=>0,"info"=>"fail");
    exit(json_encode($returndata));
}
if($type=='cdk'){
  $sqlx = "SELECT * FROM cdk WHERE cdk='$ka' ORDER BY id DESC";      //是否领取了 
  $resultx= mysql_query($sqlx, $link);  
  $rowx = mysql_fetch_array($resultx);  //查询卡信息
  if($rowx['id']!=''){
  if($rowx['user']!='0'){
    $returndata = array("errcode"=>1,"info"=>"此激活码已激活使用");
    exit(json_encode($returndata));
  }elseif($rowx['user']=='0'){
  if($row['userid']!=$rowx['userid']){
    if($rowx['dode']=='0'){ //判断是否通用 0绑定渠道 1通用
    $returndata = array("errcode"=>1,"info"=>"您无法使用其他渠道的CDK");
    exit(json_encode($returndata));
    }
  }
    if($rowx['money']=='9999'){ //包站
    $resulty= mysql_query("UPDATE user SET gm='5', huanbang='15' WHERE username='$user'", $link); 
      if($resulty){
       $resultk= mysql_query("UPDATE cdk SET user='$user', ip='$ip', tian='9999', date='$date' WHERE id='$rowx[id]'", $link); 
        if($resultk){
         $returndata = array("errcode"=>1,"info"=>"success");
         exit(json_encode($returndata));
        }else{
            $returndata = array("errcode"=>1,"info"=>"联系管理员");
    exit(json_encode($returndata));
        }
      }else{
    $returndata = array("errcode"=>1,"info"=>"联系管理员");
    exit(json_encode($returndata));
      }

    }else{ //平台币
    $resultc= mysql_query("UPDATE user SET money=money+'$rowx[money]' WHERE username='$user'", $link);    
      if($resultc){
       $resultz= mysql_query("UPDATE cdk SET user='$user', ip='$ip', tian='9999', date='$date' WHERE id='$rowx[id]'", $link); 
        if($resultz){
         $returndata = array("errcode"=>1,"info"=>"success");
         exit(json_encode($returndata));
        }else{
            $returndata = array("errcode"=>1,"info"=>"联系管理员");
    exit(json_encode($returndata));
        }
      }else{
    $returndata = array("errcode"=>1,"info"=>"联系管理员");
    exit(json_encode($returndata));
      }
    }
    $returndata = array("errcode"=>1,"info"=>"此激活码已激活使用");
    exit(json_encode($returndata));
  }
  }else{
    $returndata = array("errcode"=>1,"info"=>"卡密不存在");
    exit(json_encode($returndata));
  }
}






















?>